-
Notifications
You must be signed in to change notification settings - Fork 957
feat(Editor): new component #5407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Conversation
commit: |
| return true | ||
| } | ||
|
|
||
| if ('items' in item && item.items?.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if ('items' in item && item.items?.length) { | |
| if ('items' in item) { |
Unreachable code in the isDisabled function prevents dropdown items with empty items arrays from being properly marked as disabled. The condition at line 179 checks item.items?.length (truthy only when length > 0), then line 180 checks item.items.length === 0 which can never be true.
View Details
Analysis
Unreachable code in isDisabled prevents empty dropdown items from being disabled
What fails: The isDisabled() function in EditorToolbar.vue incorrectly marks dropdown items with empty items arrays as enabled instead of disabled. The condition at line 179 uses item.items?.length in a logical AND check, which evaluates to falsy when items is an empty array, causing the entire block to be skipped.
How to reproduce:
// Create a toolbar with a dropdown that has an empty items array
const toolbar = {
items: [
{
// Dropdown item with empty items array
items: [],
label: 'Empty Dropdown'
// No explicit disabled property
}
]
}
// Call isDisabled on the dropdown item
const item = toolbar.items[0]
isDisabled(item) // Returns: false (incorrectly enabled)
// Expected: true (should be disabled)Result: Empty dropdown returns false from isDisabled(), marking it as enabled even though there are no items to display.
Expected: A dropdown with an empty items array should be marked as disabled. The fix changes line 179 from:
if ('items' in item && item.items?.length) {to:
if ('items' in item) {This allows the empty items check at line 180 to execute properly and return true for empty dropdowns.
Root cause: The optional chaining operator ?. returns 0 (falsy in JavaScript) when items is an empty array []. The condition item.items?.length fails for empty arrays, preventing the block that handles empty items detection from executing.
π Linked issue
Resolves #2698
β Type of change
π Description
π Checklist